package vip.zhenzicheng.concurrent_program.thread.sgg.interrupt;

import java.util.concurrent.TimeUnit;

/**
 * @author zhenzicheng
 * @date 2022-06-27 19:46
 */
public class InterruptDemo3 {

  public static void main(String[] args) {
    Thread t1 = new Thread(() -> {
      while (true) {
        if (Thread.currentThread().isInterrupted()) {
          System.out.println(Thread.currentThread().getName() + "\t 中断标志位：" + Thread.currentThread().isInterrupted());
          break;
        }
        try {
          Thread.sleep(200);
        } catch (InterruptedException e) {
          Thread.currentThread().interrupt();
          e.printStackTrace();
        }
        System.out.println("---- hello InterruptDemo3");
      }
    }, "t1");

    t1.start();

    try {
      TimeUnit.SECONDS.sleep(1);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    new Thread(() -> {
      t1.interrupt();
    }, "t2").start();
  }
}
